package com.bilibili.juc.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author zuife
 * @description
 * @since 2024-04-20 16:48:35
 */
public class CompletableFutureAPI4Demo {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);
        CompletableFuture.supplyAsync(() -> {
            return 1;
        },threadPool).thenApply(v -> {
            System.out.println("22");
            return v + 2;
        }).thenApply(v -> {
            System.out.println("33");
            return v + 3;
        }).thenAccept(v -> {
            System.out.println("thenAccept:"+v);
        }).exceptionally(e -> {
            e.printStackTrace();
            System.out.println("异常：" + e.getCause().getMessage());
            return null;
        });
        System.out.println(Thread.currentThread().getName()+ "main...先去忙其他");
        threadPool.shutdown();
    }
}
